﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FaultBackService.DAL
{
    class RealTimeFaultData
    {
        /// <summary>
        /// 写入多条记录，返回记录条数
        /// </summary>
        /// <param name="faultDataList"></param>
        /// <returns></returns>
        internal int AddList(IList<Models.RealTimeFaultData> faultDataList)
        {
            using (Models.TurbineFaultContext context = new Models.TurbineFaultContext())
            {
                context.RealTimeFaultData.AddRange(faultDataList);
                return context.SaveChanges();
            }
        }

        /// <summary>
        /// 获取指定日期的数据集合
        /// </summary>
        /// <param name="day"></param>
        /// <returns></returns>
        internal IList<Models.RealTimeFaultData> GetList(DateTime day)
        {
            using (Models.TurbineFaultContext context = new Models.TurbineFaultContext())
            {
                var end = day.AddDays(1);
                return context.RealTimeFaultData
                    .Where(d => d.TimeStamp >= day && d.TimeStamp < end)
                    .OrderBy(d=>d.TimeStamp)
                    .ToList();
            }
        }
    }
}
